package com.sky.controller.admin;

import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "菜品管理接口")
@RequestMapping("/admin/dish")
@Slf4j
public class DishControLLer {
    @Autowired
    private DishService dishService;

    @GetMapping("/page")
    @ApiOperation("菜品列表接口")
    public Result findPage(DishPageQueryDTO dto) {
        //Result<PageResult> success = Result.success(pageResultVo);
        PageResult page = dishService.findPage(dto);
        return Result.success(page);
    }
    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result deleteById(@RequestParam List<Long> ids) {
        dishService.deleteById(ids);
        return Result.success();
    }
    @PostMapping
    @ApiOperation("添加菜品")
    public Result save(@RequestBody DishDTO dto) {
        dishService.save(dto);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品详情")
    public Result findById(@PathVariable("id") Long id) {
        DishVO  dto = dishService.findById(id);
        return Result.success(dto);
    }
    @PutMapping
    @ApiOperation("更新菜品")
    public Result updateDish(@RequestBody DishDTO dto) {
        Integer integer = dishService.updateDish(dto);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("修改菜品状态")
    public Result changeStatus(Integer id, @PathVariable("status") Integer status){
        Result result = dishService.changeStatus(id,status);
        return result;
    }
    @GetMapping("/list")
    @ApiOperation("根据条件查询菜品")
    public Result findByDishName(@RequestParam String categoryId) {
        List<DishVO> list = dishService.findByCategoryId(categoryId);
        return Result.success(list);
    }
}

